﻿@{
    ViewBag.Title = "保单详情";
    var id = Model != null ? Model.ID : 0;
}
@using ZBJF.Warranty.BLL
@using ZBJF.Warranty.Common.Enums.Certificate
@using ZBJF.Warranty.Common.Enums.InsuranceOrder
@using ZBJF.Warranty.WebProvider
@using ZBJF.Warranty.Common.Enums.Data
@using ZBJF.Warranty.Common.Enums.Base
@using ZBJF.Warranty.Common.Enums.InsuranceWarranty
@using ZBJF.Warranty.Model
@model ZBJF.Warranty.Model.InsuranceOrder
<style type="text/css">
    .group-header {
        font-size: 16px;
        font-weight: bold;
        color: #4f79fd;
    }

    .table td, .table th {
        text-align: center;
    }

    .list td {
        text-align: left;
    }

    .list th {
        text-align: right;
    }
</style>
<ul class="nav nav-tabs">
    <li class="active"><a href="/InsuranceOrder/Detail/@id">保单详情</a></li>
</ul>
@using (Html.BeginForm("AuditInsuranceOrder", "InsuranceOrder", FormMethod.Post, new { id = "inputForm", name = "inputForm", @class = "form-horizontal", enctype = "multipart/form-data" }))
{
    @Html.AntiForgeryToken()
    @Html.HiddenFor(c => c.ID)
    <!--最后修改时间。用于做尺度审核的并发控制，防止审核期间订单发生变化-->
    @Html.HiddenFor(c => c.LastModifyTime)
    <table class="table table-responsive table-bordered table-hover model">
        <tr>
            <th>服务合同号</th>
            <th>投保来源</th>
            <th>销售商</th>
            <th>购买方式</th>
            <th>保险卡卡号</th>
            <th>当前审核状态</th>
            <th>剩余审核时间</th>
        </tr>
        <tr>
            <td>@Html.DisplayFor(o => o.OrderNO)</td>
            <td>@ZBJF.Warranty.Common.Common.EnumHelper.Instance.GetDescription(typeof(InsuranceOrderFromType), Model.OrderFromType)</td>
            <td>@Html.DisplayFor(o => o.SaleVendorName)</td>
            <td>@ZBJF.Warranty.Common.Common.EnumHelper.Instance.GetDescription(typeof(InsuranceBuyType), Model.BuyType)</td>
            <td>@(ViewBag.productCardNo)</td>
            <td class="red">@ZBJF.Warranty.Common.Common.EnumHelper.Instance.GetDescription(typeof(InsuranceOrderStatus), Model.OrderStatus)</td>
            <td class="red">
                <span id="checkLastTimes"></span>
                <input type="hidden" id="checkTimes" value="@(ViewBag.checkTime)" />
                <input type="hidden" id="lastModifyTime" value="@(Model.LastModifyTime)" />
            </td>
        </tr>
    </table>

        <!--审核日志-->
    <p class="group-header ">审核日志</p>
    <table class="table table-responsive table-bordered table-hover">
        <tr>
            <th width="40">序号</th>
            <th width="100px">审核结果</th>
            <th width="160px">备注</th>
            <th width="160px">审核人</th>
            <th width="160px">审核时间</th>
        </tr>
        @if (Model.InsuranceOrderCheckLog.Count < 1)
        {
            <tr>
                <td colspan="6">暂无审核日志</td>
            </tr>
        }
        else
        {
            for (int i = 0; i < Model.InsuranceOrderCheckLog.Count; i++)
            {
                <tr>
                    <td>
                        @(i + 1)
                    </td>
                    <td>
                        @(Model.InsuranceOrderCheckLog.ToList()[i].CheckResult ? "审核通过" : "审核未通过")
                    </td>
                    <td>
                        @(Model.InsuranceOrderCheckLog.ToList()[i].CheckRemark)
                    </td>
                    <td>
                        @(Model.InsuranceOrderCheckLog.ToList()[i].CheckUserName)
                    </td>
                    <td>
                        @(Model.InsuranceOrderCheckLog.ToList()[i].CheckTime)
                    </td>
                </tr>
            }
        }
    </table>

    <div style="display:flex;width:100%; min-height:300px;">
        <!--基本信息-->
        <div style="flex:1; height:645px;overflow-y:auto; border-right:2px solid #ff0000; padding-right:5px;">
            <div class="tab-pane fade in active">
                <!--销售商信息-->
                <p class="group-header ">销售商信息</p>
                <table class="table table-responsive table-bordered table-hover">
                    <tr>
                        <th>销售员姓名</th>
                        <th>销售员编码</th>
                        <th>所属销售商</th>
                        <th>销售商编码</th>
                        <th>销售商地址</th>
                        <th>销售商负责人</th>
                        <th>销售商电话</th>
                    </tr>
                    <tr>
                        <td>@Html.DisplayFor(o => o.SalePersonName)</td>
                        <td>@Html.DisplayFor(o => o.ThirdSaleEmployeeId)</td>
                        <td>@Html.DisplayFor(o => o.SaleVendorName)</td>
                        <td>@(ViewBag.sellerCode)</td>
                        <td>@Html.DisplayFor(o => o.SaleAddress)</td>
                        <td>@Html.DisplayFor(o => o.SaleManagerName)</td>
                        <td>@Html.DisplayFor(o => o.SaleManagerPhone) &nbsp;</td>
                    </tr>
                </table>
                <!--保险产品基本信息-->
                <p class="group-header ">保险产品基本信息</p>
                <table class="table table-responsive table-bordered table-hover list">
                    <tr>
                        <th width="200">保险产品类型：</th>
                        <td width="200">@Html.DisplayFor(o => o.InsuranceCategoryName)</td>
                        <th width="200">保险产品名称：</th>
                        <td width="200">@Html.DisplayFor(o => o.ProductName)</td>
                        <th width="200">销售商产品名称：</th>
                        <td width="200">@(ViewBag.sellerProductName)</td>
                    </tr>
                    <tr>
                        <th width="200">第三方承保公司：</th>
                        <td width="200">@Html.DisplayFor(o => o.InsuranceCompany)</td>
                        <th width="200">承保公司分公司：</th>
                        <td width="200">@Html.DisplayFor(o => o.InsuranceCompanyBranch)</td>
                        <th width="200">保险期限：</th>
                        <td width="200">
                            @Html.DisplayFor(o => o.PolicyPeriod)
                            @ZBJF.Warranty.Common.Common.EnumHelper.Instance.GetDescription(typeof(InsuranceOrderPeriodUnit), Model.PolicyPeriodUnit)
                        </td>
                    </tr>
                </table>
                <!--投保人信息-->
                <p class="group-header ">投保人信息</p>
                <table class="table table-responsive table-bordered table-hover list">
                    <tr>
                        <th width="200">投保人姓名：</th>
                        <td width="200">@Html.DisplayFor(o => o.UserName)</td>
                        <th width="200">手机号：</th>
                        <td width="200">@Html.DisplayFor(o => o.UserPhone)</td>
                    </tr>
                    <tr>
                        <th width="200">证件类型：</th>
                        <td>@ZBJF.Warranty.Common.Common.EnumHelper.Instance.GetDescription(typeof(UserCertificateType), Model.CertificateType)</td>
                        <th width="200">证件号码：</th>
                        <td>@Html.DisplayFor(o => o.CertificateNO)</td>
                    </tr>
                </table>

                <!--投保设备信息-->
                <p class="group-header ">投保设备信息</p>
                <table class="table table-responsive table-bordered table-hover">
                    <tr>
                        <th>设备序号</th>
                        <th>设备类型</th>
                        <th>品牌</th>
                        <th>型号</th>
                        <th>设备识别码</th>
                        <th>UUID（适用于苹果智能设备）</th>
                    </tr>
                    <tr>
                        <td></td>
                        <td>@Html.DisplayFor(o => o.ProductTypeName)</td>
                        <td>@Html.DisplayFor(o => o.ProductBrandName)</td>
                        <td>@Html.DisplayFor(o => o.ProductModelName)</td>
                        <td>@Html.DisplayFor(o => o.IMEI)</td>
                        <td>@Html.DisplayFor(o => o.IDFV)</td>
                    </tr>
                </table>
                <!--投保资料-->
                <p class="group-header ">投保资料</p>
                <table class="table table-responsive table-bordered table-hover">
                    <tr>
                        <th>序号</th>
                        <th>资料类型</th>
                        <th>上传时间</th>
                        <th>查看文件</th>
                    </tr>
                    @{
                        var imgList = Model.InsuranceOrderImage.ToList();
                    }
                    @for (int i = 0; i < imgList.Count; i++)
                    {
                        <tr>
                            <td>
                                @(i + 1)
                            </td>
                            <td>
                                手机维修服务
                            </td>
                            <td>
                                @imgList[i].CreateTime
                            </td>
                            <td>
                                <a target="_blank" href="@imgList[i].ImageUrl">点击查看</a>
                            </td>
                        </tr>
                    }
                </table>
            </div>
        </div>
        <!--服务项目-->
        <div style="flex:1; height:645px;overflow-y:auto; padding-left:5px;">
            @{
                //1、手机维修服务项目
                var cellPhoneInsuranceInfo = ServiceFactory.CellPhoneInsuranceInfoServiceInstance.LoadEntities(t => t.InsuranceOrderID == Model.ID).ToList();
            }
            <ul id="myCondition" class="nav nav-tabs">
                <li class="active"><a href="#phoneRepair" data-toggle="tab">手机维修服务</a></li>
                @*<li><a href="#baseInfo" data-toggle="tab">家电清洗</a></li>*@
            </ul>
            <div id="myConditionContent" class="tab-content">
                <!--手机维修服务-->
                <div class="tab-pane fade in active" id="phoneRepair">
                    <p>
                        选择审核服务项目：
                        <select>
                            @for (int i = 0, j = cellPhoneInsuranceInfo.Count(); i < j; i++)
                            {
                                <option value="">cellPhoneInsuranceInfo[i].ServiceProjectName</option>
                            }
                        </select>
                    </p>

                    @for (int i = 0, j = cellPhoneInsuranceInfo.Count(); i < j; i++)
                    {
                        <div tagName="@cellPhoneInsuranceInfo[i].ServiceProjectName">
                            <!--基础承保条件-->
                            <p class="group-header ">基础承保条件</p>
                            <table class="table table-responsive table-bordered table-hover list">
                                <tr>
                                    <th width="200">被保险设备：</th>
                                    <td width="200">@cellPhoneInsuranceInfo[i].ProductTypeName</td>
                                    <th width="200">是否为新机投保：</th>
                                    <td width="200">@(cellPhoneInsuranceInfo[i].DeviceType.HasValue ? cellPhoneInsuranceInfo[i].DeviceType == 1 ? "是" : "否" : "否")</td>
                                    <th width="200">新机投保期限：</th>
                                    <td width="200">@(cellPhoneInsuranceInfo[i].NewMachineInsuranceTimeLimit)</td>
                                </tr>
                                <tr>
                                    <th width="200">生效等待期：</th>
                                    <td width="200">@cellPhoneInsuranceInfo[i].WaitDays 天</td>
                                    @*<th width="200">保额：</th>
                                        <td width="200">@Html.DisplayFor(o => o.InsuredAmount)</td>*@
                                    <th width="200">服务次数：</th>
                                    <td width="200">@cellPhoneInsuranceInfo[i].ServiceTimes</td>
                                </tr>
                            </table>
                            <!--维修可用配件-->
                            <p class="group-header ">维修可用配件</p>
                            <table class="table table-responsive table-bordered table-hover">
                                <tr>
                                    <th>序号</th>
                                    <th>设备类型</th>
                                    <th>配件类型</th>
                                    <th>配件等级</th>
                                </tr>
                                <tr>
                                    @if (cellPhoneInsuranceInfo[i].CellPhoneServiceProjectID.HasValue)
                                    {
                                        var temp = ServiceFactory.CellPhoneInsuranceInfoServiceInstance.GetRepairAccessoriesLevelInfo(cellPhoneInsuranceInfo[i].CellPhoneServiceProjectID.Value);
                                        if (temp != null && temp.Count() > 0)
                                        {
                                            for (int m = 0, n = temp.Count(); m < n; m++)
                                            {
                                                <td>@(m + 1)</td>
                                                <td>@temp[m].ProductTypeName</td>
                                                <td>@temp[m].AccessoriesTypeName</td>
                                                <td>@temp[m].AccessoriesLevelName</td>
                                            }
                                        }
                                        else
                                        {
                                            <td colspan="8">暂无配件信息</td>
                                        }
                                    }
                                    else
                                    {
                                        <td colspan="8">暂无配件信息</td>
                                    }
                                </tr>
                            </table>
                            <!--可用服务类型-->
                            <p class="group-header ">可用服务类型</p>
                            <table class="table table-responsive table-bordered table-hover">
                                <tr>
                                    @foreach (var item in ConvertToSelector.Instance.EnumTypeConvertToSelectList(typeof(InsuranceWarrantyMaintenanceType), 0, false))
                                    {
                                        <th>@item.Text</th>
                                    }
                                </tr>
                                <tr>
                                    @{
                                        List<int> warrantyMaintenanceTypes = ServiceFactory.InsuranceProductWarrantyMaintenanceTypesSnapshootServiceInstance.LoadEntities(t => t.InsuranceOrderServiceProjectId == cellPhoneInsuranceInfo[i].ID && t.ServiceProjectType == (byte)ServiceProductType.CellPhoneRepair).Select(t => t.InsuranceWarrantyMaintenanceTypeId).ToList();
                                    }
                                    @foreach (var item in ConvertToSelector.Instance.EnumTypeConvertToSelectList(typeof(InsuranceWarrantyMaintenanceType), 0, false))
                                    {
                                        if (warrantyMaintenanceTypes != null && warrantyMaintenanceTypes.Count > 0)
                                        {
                                            if (warrantyMaintenanceTypes.Any(o => o.ToString() == item.Value))
                                            {
                                                <td>是</td>
                                            }
                                            else
                                            {
                                                <td>否</td>
                                            }
                                        }
                                        else
                                        {
                                            <td>&nbsp;</td>
                                        }
                                    }
                                </tr>
                            </table>
                            <!--高级承保条件-->
                            <p class="group-header ">高级承保条件</p>
                            <table class="table table-responsive table-bordered table-hover">
                                @{ 
                                    CellPhoneServiceProject cellPhoneServiceProject = null;
                                    if (cellPhoneInsuranceInfo[i].CellPhoneServiceProjectID.HasValue)
                                    {
                                        cellPhoneServiceProject = ServiceFactory.CellPhoneServiceProjectServiceInstance.LoadEntities(t => t.ID == cellPhoneInsuranceInfo[i].CellPhoneServiceProjectID.Value).ToList().FirstOrDefault();
                                    }
                                }
                                <tr>
                                    <th width="400">条件</th>
                                    <th>详情</th>
                                </tr>
                                <tr>
                                    <td>可承保机型</td>
                                    <td>
                                        @if (cellPhoneServiceProject != null && cellPhoneServiceProject.UseModelTypeOption)
                                        {
                                            <a>点击查看机型列表</a>
                                        }
                                        else
                                        {
                                            <span>无</span>
                                        }
                                    </td>
                                </tr>
                                <tr>
                                    <td>可承保屏幕类型</td>
                                    @if (cellPhoneServiceProject != null && cellPhoneServiceProject.UseScreenTypeOption && cellPhoneInsuranceInfo[i].CellPhoneServiceProjectID.HasValue)
                                    {
                                        var screenType = ServiceFactory.InsuranceProductsAvailableScreenTypeServiceInstance.LoadEntities(t => t.CellPhoneServiceProjectID == cellPhoneInsuranceInfo[i].CellPhoneServiceProjectID.Value).ToList();
                                        if (screenType != null && screenType.Count > 0)
                                        {
                                            <td>
                                                @foreach (var item in screenType)
                                                {
                                                    <span>@ZBJF.Warranty.Common.Common.EnumHelper.Instance.GetDescription(typeof(ScreenTypeEnum), item.ScreenTypeCode)</span>
                                                }
                                            </td>
                                        }
                                        else
                                        {
                                            <td>无</td>
                                        }
                                    }
                                    else
                                    {
                                        <td>无</td>
                                    }
                                </tr>
                                <tr>
                                    <td>可承保价格区间</td>
                                    <td>
                                        @if (cellPhoneServiceProject != null && cellPhoneServiceProject.UsePriceOption)
                                        {
                                            <span>@cellPhoneServiceProject.ProductAmountFrom - @cellPhoneServiceProject.ProductAmountTo</span>
                                        }
                                        else
                                        {
                                            <span>无</span>
                                        }
                                    </td>
                                </tr>
                            </table>
                            <!--审核项目-->
                            <p class="group-header ">审核项目</p>
                            <table class="table table-responsive table-bordered table-hover">
                                <tr>
                                    <th>审核项目</th>
                                    <th>是否必填</th>
                                    <th>审核结果</th>
                                </tr>
                                 @{
                                     List<InsuranceProductAuditProjectConfigurationSnapshoot> auditProjectConfigurationList = ServiceFactory.InsuranceProductAuditProjectConfigurationSnapshootServiceInstance.GetAuditProjectConfigurationList(cellPhoneInsuranceInfo[i].ID,(byte)ServiceProductType.CellPhoneRepair);
                                 } 
                                @if (auditProjectConfigurationList != null)
                                {
                                    foreach (var item in auditProjectConfigurationList)
                                    {
                                        <tr>
                                            <td>@item.AuditProjectName</td>
                                            <td>@(item.IsMust?"是":"否")</td>
                                            <td>
                                                 @if (item.FieldType == (byte)FieldTypeEnum.Text)
                                                 {
                                                        <input type='text' value='@item.OptionName' />
                                                 }
                                                 else if (item.FieldType == (byte)FieldTypeEnum.CheckBoxList)
                                                 {
                                                     List<AuditProjectFieldOption> auditProjectFieldOptionList = ServiceFactory.AuditProjectFieldOptionServiceInstance.LoadEntities(t => t.AuditProjectConfigurationID == item.AuditProjectID).ToList();
                                                     if (auditProjectFieldOptionList != null)
                                                     {
                                                         foreach (var auditProject in auditProjectFieldOptionList)
                                                         {
                                                            <label>
                                                                <input type='checkbox' value="@auditProject.ID" /> @auditProject.OptionName
                                                            </label>
                                                         }
                                                     }
                                                 }
                                                 else if (item.FieldType == (byte)FieldTypeEnum.DropDownList)
                                                 {
                                                     List<AuditProjectFieldOption> auditProjectFieldOptionList = ServiceFactory.AuditProjectFieldOptionServiceInstance.LoadEntities(t => t.AuditProjectConfigurationID == item.AuditProjectID).ToList();
                                                     if (auditProjectFieldOptionList != null)
                                                     {
                                                         foreach (var auditProject in auditProjectFieldOptionList)
                                                         {
                                                            <label>
                                                                <input type='radio' value="@auditProject.ID" /> @auditProject.OptionName
                                                            </label>
                                                         }
                                                     }
                                                 }
                                                </td>
                                        </tr>

                                    }
                                }
                            </table>
                        </div>
                     }
                </div>
            </div>

        </div>
    </div>




                                        if (Model.OrderStatus == (byte)InsuranceOrderStatus.Create || Model.OrderStatus == (byte)InsuranceOrderStatus.ApprovedButNotPassed)
                                        {
                                            <p>
                                                <font style="font-weight:bold;"> 本次审核是否通过：</font>
                                                @Html.DropDownList("CheckResult", ZBJF.Warranty.WebProvider.ConvertToSelector.Instance.InitSelectList(true), new { validate = "{required:true}" })
                                            </p>
                                            <textarea id="CheckRemark" name="CheckRemark" style="width: 99%" rows="4" class="form-control" placeholder="请填写审核备注"></textarea>
                                            <div class="form-actions">
                                                <input id="btnAuditAndPass" class="btn btn-primary Edit-R" type="button" onclick="loading(this)" value="提交">
                                            </div>
                                            }
                                        }
@section scripts
{
    @Scripts.Render("~/Bundles/ImagePreview")
    <script type="text/javascript">
        $(function () {
            $("img.preview").preview();
            $("#insuranceOrderCheckLogDiv").show();

            //设置审核时间倒计时
            let checkTimes = $("#checkTimes").val();
            if (checkTimes - 0 <= 0) {
                $("#checkLastTimes").text("无限制");
            }
            else {
                let lastModifyTime = $("#lastModifyTime").val();
                //订单时间戳秒数
                let orderTimestamp = Date.parse(new Date(lastModifyTime)) / 1000;

                setInterval(function () {
                    //当前时间戳秒数
                    let currentTimestamp = Date.parse(new Date()) / 1000;
                    //剩余审核时间
                    let lastTime = (checkTimes * 60) - (currentTimestamp - orderTimestamp);
                    if (lastTime < 0) {
                        lastTime = -lastTime
                        $("#checkLastTimes").text("已超时：" + parseInt(lastTime / 60) + "分钟" + lastTime % 60 + "秒");
                    }
                    else
                        $("#checkLastTimes").text(parseInt(lastTime / 60) + "分钟" + lastTime % 60 + "秒");
                }, 1000);

            }
        });

        function loading(_this) {
            if ($("#inputForm").valid()) {
                if ($("#CheckResult").val() == "False") {
                    if (!$.trim($("#CheckRemark").val())) {
                        layer.alert("请填写审核备注");
                        return;
                    }
                }
                _this.disabled = 'disabled';
                $("#CheckRemark").val($.trim($("#CheckRemark").val()))
                document.getElementById("inputForm").submit();
            }
        }

    </script>
}
